/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.commands.template;

import org.eclipse.gef.commands.Command;
import org.eclipse.uml2.uml.TemplateParameter;
import org.eclipse.uml2.uml.TemplateSignature;

/**
 * 
 */
public class DeleteReferencedTemplateParameterCommand extends Command {
	
	
	/**
	 * context signature
	 */
	private TemplateSignature contextSignature ;
	
	/**
	 * referenced actual parameter.
	 */
	private TemplateParameter referencedParameter ;
	
	/**
	 * Default Constructor.
	 * 
	 * @param child 
	 */
	public DeleteReferencedTemplateParameterCommand(TemplateParameter referencedParameter, TemplateSignature contextSignature) {
		this.referencedParameter = referencedParameter ;
		this.contextSignature = contextSignature ;
		this.setLabel("Delete template parameter reference") ;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canUndo()
	 */
	/**
	 * 
	 * 
	 * @return 
	 */
	@Override
	public boolean canUndo() {
		return referencedParameter != null;
	}
	
	public boolean canRedo() {
		return referencedParameter != null ;
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#execute()
	 */
	/**
	 * 
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void execute() {
		contextSignature.getParameters().remove(referencedParameter) ;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#redo()
	 */
	/**
	 * 
	 */
	@Override
	public void redo() {
		execute();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	/**
	 * 
	 */
	@Override
	@SuppressWarnings("unchecked")
	public void undo() {
		contextSignature.getParameters().add(referencedParameter) ;
	}
}
